﻿using System;
using Lintop.ePos.Common.DataAccess;

namespace PowerToolsWeb.DataAccess
{
    public partial class Tpt_Producttype : DataAccessBase
    {
        //TODO: 请把你的方法添加在这里
        public bool GetByTypeName(string TypeName, int PARANTTYPEID)
        {
            string sql = @"SELECT TypeID FROM Tpt_ProductType where TypeName={0} and ParantTypeID={1}";
            sql = string.Format(sql, Helper.ToSQLParamStr(TypeName), PARANTTYPEID);
            return SelectBySql(sql);
        }
        /// <summary>
        /// 查询是否含有子类和产品数
        /// </summary>
        /// <param name="typeid"></param>
        /// <returns></returns>
        public bool GetChildAndProductCount(int typeid)
        {
            string sql = @"SELECT (count(1)+(select count(1) from Tpt_product p where p.typeid=pt.typeid)) _count  
                            FROM Tpt_ProductType pt where pt. ParantTypeID={0}";
            sql = string.Format(sql, typeid);
            return SelectBySql(sql);
        }
    }

    public partial class Tpt_ProducttypeCollection : DataAccessCollectionBase
    {
        //TODO: 请把你的方法添加在这里
        public bool ListTypeByParantId(int pid)
        {
            string sql = @"SELECT pt.*,(select count(1) from Tpt_product p where p.typeid=pt.typeid) as  productCount  FROM Tpt_ProductType pt where pt.ParantTypeID=" + pid;
            return ListBySql(sql);
        }
    }
}
